﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace VisionCloud.Core.Model.Sys
{
    [Table("SysUser")]
    public class SysUser : BaseEntity
    {
        //[Required]
        [Column(TypeName = "varchar(512)")]
        public string Code { get; set; }

        //[Required]
        [Column(TypeName = "varchar(512)")]
        public string Name { get; set; }

        //[Required]
        [Column(TypeName = "varchar(50)")]
        public string AccountNumber { get; set; }

        [Required]
        [Column(TypeName = "varchar(512)")]
        public string Password { get; set; }

        [Column(TypeName = "int4")]
        public EnumUserType? UserType { get; set; }

        [Column(TypeName = "int4")]
        public SysUser.EnumIsLocked IsLocked { get; set; }

        [Required]
        [Column(TypeName = "int4")]
        public SysUser.EnumUserStatus? Status { get; set; }

        [Column(TypeName = "varchar(50)")]
        public string Email { get; set; }

        [Column(TypeName = "varchar(50)")]
        public string PhoneNumber { get; set; }

        /// <summary>
        /// 主键
        /// </summary>
        [Key]
        [Column(TypeName = "uuid")]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public Guid YunUserGuid { get; set; }

        [Column(TypeName = "varchar(512)")]
        public string Position { get; set; }

        [Column(TypeName = "varchar(512)")]
        public string Department { get; set; }

        [Column(TypeName = "int4")]
        public EnumUserGender? Gender { get; set; }

        /// <summary>
        /// 角色
        /// </summary>
        [NotMapped]
        public String RoleNames { get; set; }

        [NotMapped]
        public Boolean IsManager { get; set; }

        public virtual ICollection<SysUserRole> SysUserRoles { get; set; }

        [Column(TypeName = "uuid")]
        public Guid? AvatarId { get; set; }

        [NotMapped]
        public String AvatarUrl { get; set; }

        public enum EnumUserGender
        { 男 = 0, 女 = 1, 未知 = 2 }

        public enum EnumUserStatus
        { 禁用 = 0, 正常 = 1 }

        public enum EnumIsLocked
        { 禁用 = 1, 正常 = 0 }

        public enum EnumUserType
        { 管理员 = -1, 主账号 = 0, 子账号 = 1, 接口账号 = 4, 游客账号 = 999 }

        [ForeignKey("AvatarId")]
        public virtual SysFile SysFile { get; set; }

        //[ForeignKey("YunUserGuid")]
        public virtual ICollection<SysOrgUser> SysOrgUsers { get; set; } = new List<SysOrgUser>();

        [Column(TypeName = "bool")]
        public bool? IsManualMeasureMan { get; set; }

        [Column(TypeName = "varchar(500)")]
        public string RoleNameList { get; set; }

        [Column(TypeName = "bool")]
        public Boolean IsPasswordNeedToChange { get; set; }

        [Column(TypeName = "varchar(500)")]
        public string CompanyNo { get; set; }

        [NotMapped]
        public int RowIndex { get; set; }

        [NotMapped]
        public List<Guid> ProjectIdList { get; set; }

        [Column(TypeName = "varchar(500)")]
        public string Company { get; set; }

        [Column(TypeName = "text")]
        public string SysOrgId { get; set; }

        /// <summary>
        /// 是否启动机器人任务，只有true才启动
        /// </summary>
        [Column(TypeName = "bool")]
        public bool? EnabledRobotTask { get; set; }

        /// <summary>
        /// 启动机器人任务的最低版本，默认为5.0.1
        /// </summary>
        [Column(TypeName = "varchar(20)")]
        public string RobotTaskMinimumVersion { get; set; } = "5.0.1";

        /// <summary>
        /// 是否开启建模权限，开启：true
        /// </summary>
        [Column(TypeName = "bool")]
        public bool EnabledModeling { get; set; } = false;

        /// <summary>
        /// 是否开启外立面权限
        /// </summary>
        [Column(TypeName = "bool")]
        public bool EnabledExternalWall { get; set; } = false;

        /// <summary>
        /// 是否开启小程序采集权限0：未授权；1：已授权
        /// </summary>
        [Column(TypeName = "bool")]
        public bool EnabledAppletCollecting { get; set; } = false;
    }
}